class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        stack<int> st;
        int i=0;
        for(auto e:pushed)
        {
            st.push(e);
              while(!st.empty()&&st.top()==popped[i])
            {
                st.pop();
                i++;
            }
        }
        if(!st.empty())
        return false;
        else 
        return true;
    }
};